<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class PHP_Paypal {

    public function __construct() {
        //parent::__construct();
        // Do something with $params
    }
    
    public function paypalConnect()
    {
        echo "Hello Paypal";
        $pp_user = "minhstone";     //The name of the user whom you added to your account using PayPal Manager, above.
        $pp_vender = "minhstone";   // 	The Merchant Login ID that you use to log into PayPal Manager.
        $pp_partner = "PayPal";     //The Payflow partner. The example below uses PayPal since PayPal Payments Advanced includes a PayPal merchant account. 
        $pp_pwd = "Minh213148";
        $pp_mode = "TEST";
        $pp_host_address = "https://pilot-payflowpro.paypal.com";
        
        $pp_amt = 1;
        
        $secureTokenID = uniqid(" ", true);
        echo "------SecureID   ".$secureTokenID;
        echo "<br>";
        $postData = "USER=".$pp_user
                ."&VENDOR=".$pp_vender
                ."&PARTNER=".$pp_partner
                ."&PWD=".$pp_pwd
                ."&CREATESECURETOKEN=Y"
                ."&SECURETOKENID=".$secureTokenID
                ."&TRXTYPE=S"
                ."&AMT=".$pp_amt;
        
        print_r($postData);
        
            $ch = curl_init();
            //$fp_err = fopen("htdocs/temporary_files/Paypal_ERROR.txt", 'w+');
            //fwrite($fp_err, date('Y-m-d H:i:s') . "\n\n"); //add timestamp to the verbose log
            curl_setopt($ch, CURLOPT_URL, $pp_host_address);
            //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            //curl_setopt($ch, CURLOPT_STDERR, $fp_err); 
            curl_setopt($ch, CURLOPT_POST, TRUE);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_SSLVERSION, 3);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 220);
            curl_setopt($ch, CURLOPT_TIMEOUT, 220);
                 
            $contents = curl_exec($ch); 
            if(!$contents)
            {
                echo "<br>To order, please contact us...";
            }
            parse_str($contents,$respond_arr);
            echo "<pre>";
            print_r($respond_arr);
            echo "</pre>";
            curl_close($ch);
            //fclose($fp_err);
            //echo $contents;
        echo "<iframe src=\"https://payflowlink.paypal.com?
MODE=TEST&SECURETOKENID=".$secureTokenID."&SECURETOKEN=".$respond_arr['SECURETOKEN']."\"
name=\"test_iframe\" scrolling=\"no\" width=\"570px\" height=\"540px\">allowtransparency='true'></iframe>";
    
    }

}
